<?php
/**
 * PHP 选择排序
 * Created by PhpStorm.
 * User: netstan
 * Date: 14-5-10
 * Time: 下午3:52
 */


/**
 * 选择排序
 * @param $arr  @需要排序的数组
 */
function select_Sort(&$arr){

    $size = count($arr);
    $tmp = 0;

    for($i = 0; $i < $size-1; $i++){
        $min_Val = $arr[$i];
        $min_Index = $i;

        for($j = $i+1; $j < $size; $j++){
            if($min_Val > $arr[$j]){
                $min_Val = $arr[$j];
                $min_Index = $j;
            }
        }

        // 交换
        $tmp = $arr[$i];
        $arr[$i] = $arr[$min_Index];
        $arr[$min_Index] = $tmp;
    }

}

$arr = array(1,2,3,0,-9,-8,-1,99,999);

select_Sort($arr);
var_dump($arr);
